﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Citrix.XaAdminMobile.ViewModel;
using Citrix.Cmp;

namespace Citrix.XaAdminMobile
{
    /// <summary>
    /// Helper to display simple mobile style modal popup dialogs.
    /// </summary>
    internal static class PopupHelper
    {
        /// <summary>
        /// Shows a popup with OK/Cancel buttons and a message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>True if the user selected ok, false if they selected cancel.</returns>
        public static bool ShowOkCancelPopup(string message)
        {
            PopupViewModel popupVm = new PopupViewModel();
            PopupWindow window = new PopupWindow();
            window.Title = Properties.Resources.PopupTitle;

            PopupButtonViewModel ok = new PopupButtonViewModel(window, PopupButtonType.OK);
            PopupButtonViewModel cancel = new PopupButtonViewModel(window, PopupButtonType.Cancel);
            PopupMessageViewModel messageVm = new PopupMessageViewModel(message);

            popupVm.AddMessage(messageVm);
            popupVm.AddButton(ok);
            popupVm.AddButton(cancel);

            window.DataContext = popupVm;
            ClientKeyboardController.HideKeyboard();
            
            App app = App.Current as App;
            if (null != app && null != app.MainWindow)
            {
                window.Owner = app.MainWindow;
            }

            return window.ShowDialog() ?? false;
        }

        /// <summary>
        /// Shows a simple acknowledgement dialog with an OK button.
        /// </summary>
        /// <param name="args">The popup messages to show on the dialog.</param>
        public static void ShowAcknowledgePopup(params string[] args)
        {
            PopupViewModel popupVm = new PopupViewModel();
            PopupWindow window = new PopupWindow();
            window.Title = Properties.Resources.PopupTitle;

            PopupButtonViewModel ok = new PopupButtonViewModel(window, PopupButtonType.OK);
            if (null != args)
            {
                foreach (var m in args)
                {
                    PopupMessageViewModel messageVm = new PopupMessageViewModel(m);
                    popupVm.AddMessage(messageVm);
                }
            }

            popupVm.AddButton(ok);

            window.DataContext = popupVm;
            ClientKeyboardController.HideKeyboard();

            App app = App.Current as App;
            if (null != app && null != app.MainWindow)
            {
                window.Owner = app.MainWindow;
            }

            window.ShowDialog();
        }
    }
}
